package cat.sun.dialogs;

import cat.sun.R;
import cat.sun.adapters.ThemeDialogAdapter;
import cat.sun.themes.ThemeConstants;
import cat.sun.themes.ThemeName;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ThemesDialog extends DialogFragment
{
	public static ThemesDialog newInstance()
	{
		ThemesDialog dialog = new ThemesDialog();		
		return dialog;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{		
		super.onCreate(savedInstanceState);
		setStyle(DialogFragment.STYLE_NO_FRAME, 0);	
		//setCancelable(false);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
	{
		View view = inflater.inflate(R.layout.dialog_themes, container,false);		
		final Context context = getActivity();		
				
		TextView title = (TextView) view.findViewById(R.id.dialog_themes_title);
		title.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf"));
		
		ListView list = (ListView) view.findViewById(R.id.dialog_themes_list);
		
		String currentTheme = context.getSharedPreferences(ThemeConstants.bundleTag, 0).getString(ThemeConstants.savedTheme, ThemeName.DEFAULT_HOLO_DARK_THEME.toString());
		ThemeName [] names = ThemeName.values();
		int cur = 0;
		for (int i=0;i<names.length;i++)
			if (names[i].toString().equals(currentTheme))
				cur = i;
		
		ThemeDialogAdapter mainMenuAdapter = new ThemeDialogAdapter(context,cur);		
		list.setAdapter(mainMenuAdapter);
		
		final ImageView close = (ImageView) view.findViewById(R.id.dialog_themes_close);
		
		close.setOnClickListener(new View.OnClickListener() 
		{			
			@Override
			public void onClick(View v) 
			{				
	            dismiss();
			}			
		});
		
		return view;		
	}
}
